﻿using ActionFilterPlugin;
using CommonEntity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using NetCore6WebAPITestOneEntity;
using NetCore6WebAPITestOneRequestEntity;
using NetCroe6WebAPITestOneBusiness;
using System.Net;

namespace NetCroe6WebAPITestOne.Controllers
{
    [ApiController]
    [Route("api/Userinfo")]
    [Produces("application/json")]//响应内容支持
    [ServiceFilter(typeof(ComActionFilter))]//过滤器身份验证
    public class UserinfoController : ControllerBase
    {
        UserinfoBusiness userinfoBusiness;

        public UserinfoController(UserinfoBusiness userinfoBusiness)
        {
            this.userinfoBusiness = userinfoBusiness;
        }

        [HttpPost("PostUser")]
        [ProducesResponseType((int)HttpStatusCode.OK)]
        public object PostUser([FromBody]UserinfoModel user)
        {
            return new
            {
                status = 200
            };
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        [HttpGet("{userid:long}/GetUserModel")]
        [ProducesResponseType(typeof(ViewModelBase<UserinfoModel>), (int)HttpStatusCode.OK)]
        public ViewModelBase GetUserModel(long userId)
        { 
            return userinfoBusiness.GetUserModel(userId);
        }

        /// <summary>
        /// 获取用户分页数据
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        [HttpPost("GetUsers")]
        [ProducesResponseType(typeof(ViewModelBase<Boolean>), (int)HttpStatusCode.OK)]
        public ViewModelBase GetUsers(GetUsersRequestViewModel p) {
            return userinfoBusiness.GetUsers(p);
        }

        /// <summary>
        /// 新增用户
        /// </summary>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        [HttpPost("InserUserModel")]
        [ProducesResponseType(typeof(ViewModelBase<Boolean>), (int)HttpStatusCode.OK)]
        public ViewModelBase InserUserinfo([FromBody] InserUserinfoViewModel userinfo) {
            return userinfoBusiness.InserUserinfo(userinfo);
        }
    }
}
